package com.camel.auth.config;

import cn.dev33.satoken.interceptor.SaInterceptor;
import cn.dev33.satoken.stp.StpUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author camel
 */
@Configuration
public class SaTokenConfig implements WebMvcConfigurer {

    @Autowired
    private CorsInterceptor corsInterceptor;


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new SaInterceptor(hadle -> StpUtil.checkLogin()))
                .addPathPatterns("/**")
                .excludePathPatterns("/sso/**", "/sa-res/**");

        registry.addInterceptor(corsInterceptor).addPathPatterns("/**");
    }
}
